<script type="text/javascript">
  function getAddress(zipcode) {
    var search_url = '/index/get_address';
	  $.ajax({
	    url: search_url,
	    type: 'GET',//POSTだと認証エラーが発生する
	    dataType: 'text',
	    data: {zipcode: zipcode},
	    success: function(data){
        document.getElementById("maker_address").value = data;
	    },
	    error: function(){
	      alert("通信に失敗しました");
	    }
	  })
  }
</script>

<h2><%= @maker.name.blank? ? "新規蔵元" : @maker.name %>の編集</h2>
<%= form_for(@maker, :url => {:controller => :admin_makers, :action => :update}) do |f| %><br />
  <%= f.hidden_field :id, { :value => @maker.id } %>
  <%= f.radio_button :is_show, 1, :checked => (@maker.is_show == true) %>表示
  <%= f.radio_button :is_show, 0, :checked => (@maker.is_show == false) %>非表示<br />
	<br />
  都道府県<%= f.select(:prefecture, Prefecture.all.collect { |i| [i.name, i.id] }) %><br />
  <br />
  蔵元名<%= f.text_field :name %><br />
  <br />
  読み<%= f.text_field :name_yomi %><br />
  <br />
  設立<%= f.date_select :establishment, :use_month_numbers => true, :start_year => Time.now.year-500, :default => -50.years.from_now %><br />
  <br />
  水<%= f.text_field :water %><br />
  <br />
	
  緯度<%= f.text_field :latitude %><br />
  経度<%= f.text_field :longtitude %><br />
	<div id="map_canvas"></div>
	<br />

  <% puts params %>
	マップのポップアップ<br />
  <%= f.text_area :pr, {:class => "ckeditor"} %><br />
  <br />
  記事<br />
  <%= f.text_area :article, {:class => "ckeditor"} %><br />
	<!-- 画像プレビュー -->
	<script type="text/javascript">
		$(function(){
		  $("#image_maker").change(function(){
		    ajax_post();
		  });
		  $("#image_production").change(function(){
		    ajax_post();
		  });
		  $("#image_type").change(function(){
		    ajax_post();
		  });
		});
		
		function ajax_post(){
		  var maker_val = $("#image_maker").val();
		  var prod_val = $("#image_production").val();
		  var type_val = $("#image_type").val();
		  $.ajax({
		    url: "/images/get_variable_images",
		    type: 'GET',
		    dataType: 'text',
		    data: {maker:maker_val, production:prod_val, image_type:type_val},
		    success: function(data){
		      if(data.length>0){
		        $("#images").html(data);
		      } else {
		        $("#images").html("no images");
		      }
		    },
		    error: function(){
		      alert("通信に失敗しました");
		    }
		  })
		}
		
	</script>
  <table border="1">
  <tr><td>画像アドレスのコピー</td></tr>
  <tr><td>
  <%= form_tag do %>
     蔵元
    <%= select_tag(:image_maker, options_for_select(Maker.order(:name_yomi).all.collect {|i| [i.name, i.id]}.insert(0, ''), params[:image].nil? ? 0 : params[:image][:maker])) %>
    <br />
    銘柄
    <%= select_tag(:image_production, options_for_select(Product.order(:name_yomi).all.collect {|i| [i.name, i.id]}.insert(0, ''), params[:image].nil? ? 0 : params[:image][:production])) %>
    <br />
    画像タイプ
    <%= select_tag(:image_type, options_for_select(MasterImageType.all.collect {|i| [i.name, i.id]}, params[:image].nil? ? 0 : params[:image][:image_type])) %>
    <br />
  <% end %>
  </td></tr>
  <tr><td>
  	<div id='images'></div>
  </td></tr>
  </table>
  <br />
	
  メールアドレス<%= f.email_field :mail_address %><br />
  <br />
  郵便番号<%= f.text_field :zipcode %><br />
	<input type="button" value="住所取得" onClick="getAddress(document.getElementById('maker_zipcode').value)" >
  <br />
  住所<%= f.text_field :address %><br />
  <br />
  電話<%= f.text_field :phone %><br />
  <br />
  FAX<%= f.text_field :fax %><br />
  <br />
  見学の可否<%= f.select :is_observe, [["不可", 0], ["可", 1]], :selected => @maker.is_observe ? 1 : 0 %><br />
  <br />

	<br />
	<%= f.submit "保存" %>
<% end %>
